<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<script type="text/javascript">
	$(function() {
		var $grid = $('#grid_user');
		var $title = '用户';
		var $baseUrl = 'sys/user';
		$grid.datagrid({
			title : $title + '列表',
			url : $baseUrl + '/page?sort=sort,asc',
			dialog : {
				url : $baseUrl,
				name : $title,
				create : {
					width : 660,
					height :500
				},
				update : {
					width : 660,
					height : 500
				},
				resetPassword : {
					name : '重置密码',
					title : '重置用户密码',
					url : 'password'
				},
				role : {
					width : 880,
					height : 368,
					name : '设置角色',
					title : '设置用户角色',
					url : 'role',
					href : 'sys/role/dialog',
					buttons : [ $.dialog.buttons.save, $.dialog.buttons.close ],
					onSubmitSuccess : function( data, options){
						$.dialog.close();
						var $grid = $('#grid_user_role')
						$.crudgrid.gridMethod($grid, 'reload');
					}
				},
				position : {
					width : 480,
					height : 668,
					name : '设置岗位',
					title : '设置用户岗位',
					url : 'position',
					href : 'sys/position/dialog',
					buttons : [ $.dialog.buttons.save, $.dialog.buttons.close ],
					onSubmitSuccess : function( data, options){
						$.dialog.close();
						var $grid = $('#grid_user_position')
						$.crudgrid.gridMethod($grid, 'reload');	
					}
				},
				search : {
					width : 880,
					height : 468
				}
			},
			pagination : true,
			pageSize : 50,
			pageList : [ 50, 100, 200 ],
			columns : [ [ {
				field : 'username',
				title : '员工号',
				width : 80
			}, {
				field : 'name',
				title : '姓名',
				width : '80',
				formatter:function(value,row){return row.cade==null?'':row.cade.name;}
			}, {
				field : 'dept',
				title : '部门',
				width : 120,
				formatter : function(value, row, index) {
					return row.dept ? row.dept.name : '';
				}
			}, {
				field : 'telphone',
				title : '手机',
				width : 80
			}, {
				field : 'idNo',
				title : '身份证号',
				width : 120,
				formatter:function(value,row){return row.cade==null?'':row.cade.idNo;}
			}, {
				field : 'status',
				title : '员工状态',
				width : 60,
				formatter : function(value, row, index) {
					return row.status ? row.status.name : '';
				}
			}, {
				field : 'sex',
				title : '性别',
				width : 40,
				formatter : function(value, row, index) {
					return row.cade==null?'':row.cade.sex;
				}
			}, {
				field : 'hireDate',
				title : '入职日期',
				width : 120
			}, {
				field : 'leaveDate',
				title : '离职日期',
				width : 120
			}, {
				field : 'qq',
				title : 'QQ',
				width : 60
			}, {
				field : 'email',
				title : '邮件',
				width : 80
			}, {
				field : 'education',
				title : '学历',
				width : 60,
				formatter : function(value, row, index) {
					return row.education ? row.education.name : '';
				}
			}, {
				field : 'major',
				title : '专业',
				width : 100
			}, $.fields.description, $.fields.sort, $.fields.status ] ],
			toolbar : [<sec:authorize access="hasRole('HRM_ADD') or hasRole('DEVELOPMENT_MODE')"> $.crudgrid.buttons.create,</sec:authorize><sec:authorize access="hasRole('HRM_EDIT') or hasRole('DEVELOPMENT_MODE')"> $.crudgrid.buttons.update, </sec:authorize><sec:authorize access="hasRole('HRM_DELETE') or hasRole('DEVELOPMENT_MODE')">$.crudgrid.buttons.remove,</sec:authorize> '-', 
				<sec:authorize access="hasRole('HRM_ROLE') or hasRole('DEVELOPMENT_MODE')">{
				text : '角色',
				iconCls : 'icon-role',
				handler : function() {
					$.crudgrid.getGrid(this).datagrid('dialog.update', 'role');
				}
			}, </sec:authorize><sec:authorize access="hasRole('HRM_RESET') or hasRole('DEVELOPMENT_MODE')">{
				iconCls : 'icon-key',
				text : '重置密码',
				handler : function() {
					$.crudgrid.getGrid(this).datagrid('dialog.remove', 'resetPassword');
				}
			}, </sec:authorize>'-',$.crudgrid.buttons.refresh, $.crudgrid.buttons.search,$.crudgrid.buttons.clearSearch ],
			onSelect : function(index, row) {
				$('#grid_user_role').datagrid('unselectAll').datagrid('load', {
					'joinIds' : row.id
				});
				$('#grid_user_position').datagrid('unselectAll').datagrid('load', {
					'joinIds' : row.id
				});
			}
		});
	});
</script>
<script type="text/javascript">
	$(function() {
		var $grid = $('#grid_user_role');
		var $title = '角色';
		var $baseUrl = 'sys/user/role';
		$grid.datagrid({
			singleSelect : false,
			title : $title + '列表',
			url : $baseUrl + '/selected?sort=sort,asc&source=true',
			columns : [ [ $.fields.name, {
				field : 'source',
				title : '来源',
				width : '80'
			}, $.fields.status ] ],
			onClickRow : function(index, row) {
				$(this).datagrid('linkgrid.load', {
					linkgrid : $('#grid_user_permission'),
					field : 'joinIds'
				});
			},
			onAjaxSuccess : function(data) {
				$(this).datagrid('selectAll');
				$(this).datagrid('linkgrid.load', {
					linkgrid : $('#grid_user_permission'),
					field : 'joinIds'
				});
			},
			toolbar : [ $.crudgrid.buttons.refresh, '-' ]
		}).treegrid('filter.init');
	});
</script>
<script>
	$(function() {
		var $grid = $('#grid_user_permission');
		var title = '权限';
		var $baseUrl = 'sys/permission';
		$grid.treegrid({
			border : false,
			singleSelect : false,
			title : title + '列表',
			url : $baseUrl + '/treeGrid?sort=sort,asc',
			onLoadSuccess : function(data) {
				$(this).treegrid('initSelected');
			},
			onBeforeSelect : function(row) {
				if (!row.selected) {
					return false;
				}
			},
			onBeforeUnselect : function(row) {
				return false;
			},
			columns : [ [ $.fields.permission.checkbox('permissionIds', true), $.fields.treeField, $.fields.status ] ],
			toolbar : [ $.crudgrid.buttons.refresh, '-' ]
		}).treegrid('filter.init');
	});
</script>
<script type="text/javascript">
	$(function() {
		var $grid = $('#grid_user_position');
		var $title = '岗位';
		var $baseUrl = 'sys/user/position';
		$grid.datagrid({
			singleSelect : true,
			title : $title + '列表',
			url : $baseUrl + '/selected?sort=sort,asc',
			columns : [ [ {
				field : 'deptName',
				width : 120,
				title : '部门'
			}, $.fields.name, $.fields.status ] ],
			onClickRow : function(index, row) {
				var $linkgrid = $('#grid_user_duty');
				var rows = $(this).datagrid('getSelections');
				var queryParam = [];
				for (var i = 0; i < rows.length; i++) {
					queryParam.push(rows[i].id.split("_")[1]);
				}
				$linkgrid.datagrid('unselectAll');
				if (queryParam.length > 0) {
					var p = {};
					p['joinIds'] = queryParam.join(',');
					$linkgrid.treegrid('load', p);
				}
			},
			toolbar : [ $.crudgrid.buttons.refresh, '-' ]
		}).treegrid('filter.init');
	});
</script>
<script>
	$(function() {
		var $grid = $('#grid_user_duty');
		var title = '职责';
		var $baseUrl = 'sys/duty';
		$grid.treegrid({
			border : false,
			singleSelect : false,
			title : title + '列表',
			url : $baseUrl + '/treeGrid?sort=sort,asc',
			onLoadSuccess : function(data) {
				$(this).treegrid('initSelected');
			},
			onBeforeSelect : function(row) {
				if (!row.selected) {
					return false;
				}
			},
			onBeforeUnselect : function(row) {
				return false;
			},
			columns : [ [ $.fields.permission.checkbox('dutyIds', true), $.fields.treeField, $.fields.status ] ],
			toolbar : [ $.crudgrid.buttons.refresh, '-' ]
		}).treegrid('filter.init');
	});
</script>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',split:true,border:false">
		<table id="grid_user"></table>
	</div>
	<div data-options="region:'east',split:true" style="width: 390px;">
		<div class="easyui-tabs" data-options="fit:true">
			<div title="角色权限">
				<div class="easyui-layout" data-options="fit:true,border:false">
					<div data-options="region:'north',border:false" style="height: 300px;">
						<table id="grid_user_role"></table>
					</div>
					<div data-options="region:'center'" style="width: 390px;">
						<table id="grid_user_permission"></table>
					</div>
				</div>
			</div>
			<div title="岗位职责">
				<div class="easyui-layout" data-options="fit:true,border:false">
					<div data-options="region:'north',border:false" style="height: 300px;">
						<table id="grid_user_position"></table>
					</div>
					<div data-options="region:'center'" style="width: 390px;">
						<table id="grid_user_duty"></table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
